<?php
namespace Home\Controller;
use Think\Controller;
class SssdController extends Controller {
    public function index(){
        indexRvent();//测算首页执行事件
        $this->assign('titleName',titleName('Sssd',1));//首页名称

        indexRequest($_REQUEST);//测算首页接收数据处理
        indexInterface('Sssd','SSSD','sssdcs');//首页公共函数

        //渠道获取ID
        $channelID=obtain_channelID('SSSD');
        $this->assign('channelID',$channelID);

        $this->assign('imgPath',cookie('imgPath'));
        $this->assign("orderidnum",'Sssd');
        $this->display("Sssd/ZM_index");
    }
    public function zhifu(){
        $this->assign('titleName',titleName('Sssd',2));//首页名称
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        zhifuInterface('Sssd','SSSD',65);//支付页公共

        $channel=cookie('channel');
        $datetype=cookie('datetype');if($datetype=='')$datetype=0;
        if(cookie('zsex')==1){$zsex='男';}else{$zsex='女';}
        zwmp(cookie('zymd'), cookie('zhour'),$zsex,'sizhu');
        $sizhu=I('globals.sizhu');
        $this->assign('sizhu',$sizhu);//Z四柱

        if($datetype==1){
            $this->assign('datetype',"农历 ".cookie('zyinli')." ".mb_substr($sizhu[3],1,1,'utf-8')."时");
        }else{
            $this->assign('datetype',"阳历 ".cookie('zyangli'));
        }

        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            if (strpos($user_agent, 'Windows') == true||strpos($user_agent,'Mac') == true) {
                //Windows 电脑访问
                if(channelSaoma($channel)){
                    $this->assign('pc',1);
                    $saomaUrl=wxsaoma('SSSD','三世书-六道轮回',cookie('orderid'));//微信扫码回调参数
                    $this->assign('wxsaoma',$saomaUrl);
                }
            }
        }else{
            $xml=wxgzhzf('SSSD','三世书-六道轮回',cookie('orderid'));//公众号支付回调参数
            $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $val = json_decode(json_encode($xmlstring),true);
            $noncestr=noncestr(15);//随机字符串
            $timestamp=time();//时间戳

            $stringA="appId=".cookie('APPID')."&nonceStr={$noncestr}&package=prepay_id={$val['prepay_id']}&signType=MD5&timeStamp={$timestamp}";
            $stringSignTemp=$stringA."&key=".cookie('wxKEY');
            $sign=strtoupper(md5($stringSignTemp));

            $this->assign('timeStamp',$timestamp);
            $this->assign('nonceStr',$noncestr);
            $this->assign('package','prepay_id='.$val['prepay_id']);
            $this->assign('signType','MD5');
            $this->assign('paySign',$sign);
            $this->assign('appId',cookie('APPID'));
        }

        $this->assign('csNameJump',U('Sssd/jieguoye','',false).'?ordernum='.cookie('orderid'));//支付成功跳转地址

        $this->assign('channel',cookie('channel'));
        $this->assign('znickname',cookie('znickname'));
        $this->assign('sex',cookie('zsex'));
        $this->assign('imgPath',cookie('imgPath'));
        $this->display("Sssd/ZM_zhifu");
    }
    public function jieguoye(){
        jieguoInterface();//结果页公共函数
        $this->assign('titleName',titleName('Sssd',3));//首页名称
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        $channel=cookie('channel');

        if(empty($_REQUEST['ordernum'])){
        }else{
            $ordernum=$_REQUEST['ordernum'];
            $arrdata[0]=jieguoyeArrData($ordernum);
            $phone=$arrdata[0]['phone'];$this->assign('phone',$phone);
            $email=$arrdata[0]['email'];$this->assign('email',$email);
            // if($channel=='qudao100'){
            $this->assign('phonebindNum',1);//手机绑定弹窗
            $wzurl=wxJsdkData();
            $this->assign('jgOrderUrl',$wzurl);
//                $arrdata=S('sm_h5test|'.$ordernum);
//                $arrdata['phone']='';
//                $arrdata['email']='';
//                S('sm_h5test|'.$ordernum,$arrdata,2592000);//2592000为30天
            // }

            $ymd=$arrdata[0]['year'].'-'.str_pad($arrdata[0]['month'],2,"0",STR_PAD_LEFT).'-'.str_pad($arrdata[0]['day'],2,'0',STR_PAD_LEFT);
            $hour=$arrdata[0]['hour'];
            cookie('zymd',$ymd,604800);
            cookie('zhour',$arrdata[0]['hour'],604800);
            cookie('znickname',$arrdata[0]['username'],604800);
            cookie('zsex',$arrdata[0]['sex'],604800);

            $y=mb_substr(cookie('zymd'),0,4);//年
            $m=mb_substr(cookie('zymd'),5,2); //月
            $d=mb_substr(cookie('zymd'),8,2);//日
            $zyinli=yinli($y,$m,$d);
            cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.cookie('zhour').'时',604800);//阳历
            $zyangli=cookie('zyangli');
            cookie('orderid',$arrdata[0]['ordernum'],604800);
        }

        if($_REQUEST['birthday']){//接口参数使用
            $ymdArr=explode('-',$_REQUEST['birthday']);
            $ymd=$ymdArr[1].'-'.$ymdArr[2].'-'.$ymdArr[3];
            $hour=$ymdArr[4];
        }

        //一对一亲算下单
        $QSorder=new \Library\toolOrder();
        $wxzhifuArr=$QSorder->QSorderXD();
        if($wxzhifuArr==1){
            $this->assign('qsPay',1);
        }else{//更新数据
            if (strpos($user_agent, 'MicroMessenger') == false) {
                //非微信浏览器访问
            }else{
                $this->assign('timeStamp',$wxzhifuArr['timeStamp']);
                $this->assign('nonceStr',$wxzhifuArr['nonceStr']);
                $this->assign('package',$wxzhifuArr['package']);
                $this->assign('signType',$wxzhifuArr['signType']);
                $this->assign('paySign',$wxzhifuArr['paySign']);
                $this->assign('appId',$wxzhifuArr['appId']);
            }
        }


        if(cookie('zsex')==1){$zsex='男';
        }else{$zsex='女';
        }
        zwmp($ymd,$hour,$zsex,'sizhu');
        $sizhu=I('globals.sizhu');
        $xiys=I('globals.xiys');
        $dayunss=I('globals.dayunss');//大运十神
        $ssarray=array();
        array_push($ssarray,implode(I('globals.nianzhuss')));
        array_push($ssarray,implode(I('globals.yuezhuss')));
        array_push($ssarray,implode(I('globals.shizhuss')));

        wuxing_healthy($xiys);
        $wuxing=I('globals.wuxing');
        cookie('zyinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2].' '.mb_substr($sizhu[3],1,1,'utf-8').'时',604800);//阴历
        $zyinli=cookie('zyinli');
        $selectArr=array(
            'sizhu'=>$sizhu,
            'nianzhuss'=>$ssarray,
            'canggan'=>I('globals.canggan'),
            'zhishen'=>I('globals.zhishen'),
            'sizhuny'=>I('globals.sizhuny'),
            'bzdishi'=>I('globals.bzdishi'),
            'wxsqs'=>I('globals.wxsqs'),
            'xiys'=>I('globals.xiys'),
            'taiyuan'=>I('globals.taiyuan'),
            'rikong'=>I('globals.rikong'),
            'dayun'=>I('globals.dayun'),
            'dayunx'=>I('globals.dayunx'),
            'dayuny'=>I('globals.dayuny'),
            'dayungz'=>I('globals.dayungz'),
            'dayunss'=>$dayunss,
            'zyinli'=>$zyinli,
            'zyangli'=>$zyangli,
            'wuxing'=>$wuxing,
        );

        $DataClass=new \Library\Data();
        $dataArr=$DataClass->sanshishu($sizhu,$ymd,$hour);
        $sndyClass=new \Library\ShinianDy();
        $shinianDy=$sndyClass->shinianDy($ymd,$hour);$dataArr['shinianDy']=$shinianDy;
        $kaiyun=$sndyClass->shiwu($ymd,$hour);$dataArr['kaiyun']=$kaiyun;
        $selectArr['data']=$dataArr;
        $this->assign('ArrData',$selectArr);

        $dataYearType=cookie('dataYearType');//2021标识
        if(empty($dataYearType)){$dataYearType=2020;}
        $this->assign('yearName',$dataYearType);

        //dump($selectArr);
        $this->display("Sssd/ZM_jieguoye");
    }
    public function paywx(){//H5微信支付
        H5ZMwxzhifu('SSSD','三世书-六道轮回',cookie('orderid'),'Sssd');//知命
    }
    public function pay(){//支付宝支付
        $this->assign('ordername1','三世书-六道轮回');
        $this->assign('ordername2','知命-三世书-六道轮回');
        $this->display("Index/pay");
    }

}